import Vue from 'vue'
import Vuex from 'vuex'

const StoreKey = 'LOGIN_INFO'

Vue.use(Vuex)

const getStoreAccount = () => {
  let data = window.localStorage.getItem(StoreKey)
  if (data) {
    data = JSON.parse(data)
  } else {
    data = null
  }
  return data
}

export default new Vuex.Store({
  state: {
    currentLoginAccount: getStoreAccount()
  },
  mutations: {
    setCurrentLoginAccount (state, payload) {
      state.currentLoginAccount = payload
      window.localStorage.setItem(StoreKey, JSON.stringify(payload))
    }
  },
  actions: {
  },
  modules: {
  }
})
